#!/bin/bash

# echo $@
# Define the tasks
valid_tasks=('RE_STRICT')
# valid_tasks=('RE')
# help_tasks=('NER' 'RC_NO_ICL' 'TE' 'EPE')
# num_aux_tasks=1

# Other parameters
# dataset_name=('New-York-Times-RE')
# dataset_name=('conll04')
# dataset_name=('semval-RE')
dataset_name=('semval-RE')

# dataset_name=($1)
# merge_dataset_dir=$2
merge_dataset_dir=0921025639

# seed=$3
seed=100
few_shot_num=50
# valid_tasks=$4
# shift 4

aug_rules='origin'

# aug_rules=$@
# aug_rules='add_triple origin remove_triple replace_same_type_entity swap_triple'
# aug_rules='origin'

# aug_rules='add_triple replace_same_type_entity'
# aug_rules='add_triple add_same_type_triple'

# dataset_name=('SciECR_with_entity_processed')
all_answer_types=('svo')
traing_num=(-1)
context_format='conditions'

# Array to store all task combinations
declare -a all_combinations

# Function to generate all combinations
generate_combinations() {
    local prefix="$1"
    local tasks=("${!2}")

    # Add current combination to the array
    all_combinations+=("$prefix")

    # Generate combinations recursively
    for i in "${!tasks[@]}"; do
        local new_prefix="$prefix ${tasks[i]}"
        local new_tasks=("${tasks[@]:i+1}")
        generate_combinations "$new_prefix" new_tasks[@]
    done
}

# Generate all combinations
# generate_combinations "" help_tasks[@]

# all_combinations=("RE" "NER RE" "NER RC_NO_ICL RE" "TE RE" "EPE RE" "TE EPE RE")
# all_combinations=("NER TE" "EPE" "NER RC_NO_ICL TE")
# all_combinations=("NER RC_NO_ICL TE EPE")
# all_combinations=("NER TE")
# all_combinations=("TE EPE")
all_combinations=("")

for combination in "${all_combinations[@]}"; do
    echo "$combination"
done

# echo "Running with tasks: $valid_tasks"
# echo "rules: $aug_rules"
# echo "dataset: $dataset_name"
# echo "merge_dataset_dir: $merge_dataset_dir"
# echo "seed: $seed"

# Function to run the Python script
run_python_script() {
    # local tasks="$valid_tasks"
    local train_tasks="$1"
    for dataset in "${dataset_name[@]}"; do
        for training_n in "${traing_num[@]}"; do
            for answer_type in "${all_answer_types[@]}"; do
                echo "Running with tasks: $train_tasks"
                python train_hf3.py \
                    --path_to_model_config="./configs/hf_config.yaml" \
                    --dataset_name=$dataset \
                    --answer_template=$answer_type \
                    --context_format=$context_format \
                    --training_num=$training_n \
                    --tasks="$train_tasks" \
                    --merge_dataset_dir=$merge_dataset_dir \
                    --few_shot_num=$few_shot_num \
                    --rules="$aug_rules"

            done
        done
    done
}

# # Run the Python script for all combinations
for combination in "${all_combinations[@]}"; do
    run_python_script "$combination"
done
